<?php
include "../include/global.php";
include "../include/admin_check.php";
include "../../FCKeditor/fckeditor.php";
$xtpl = new XTemplate ("daytripWrite.htm");
include "setting.php";
//
include "../include/function.php";
$xtpl->assign("left_panel", left_panel());
$xtpl->assign("header_panel", header_panel());
$xtpl->assign("footer_panel", footer_panel());

// ++ lang
if($lang=='v'){
	$xtpl->assign('type_vietnamese', 'onkeyup="initTyper(this)"');
}
$xtpl->assign("title", Daytrip);
$xtpl->assign("lbl_search", Search);
$xtpl->assign("lbl_no", No);
$xtpl->assign("lbl_country", Country);
$xtpl->assign("lbl_travelstyle", TravelStyle);
$xtpl->assign("lbl_city", City);
$xtpl->assign("lbl_name", Name);
$xtpl->assign("lbl_price", Price);
$xtpl->assign("lbl_brief", Brief);
$xtpl->assign("lbl_content", Content);
$xtpl->assign("lbl_image", Image);
$xtpl->assign("lbl_position", Position);
$xtpl->assign("lbl_active", Active);
$xtpl->assign("lbl_isdestination", IsDestination);
$xtpl->assign("lbl_metadescription", MetaDescription);
$xtpl->assign("lbl_metakeyword", MetaKeyword);
$xtpl->assign("lbl_save", Save);
$xtpl->assign("lbl_save_add", SaveAdd);
$xtpl->assign("lbl_cancel", Cancel);
// -- lang

$ID=intval($_GET['ID']);
if($ID){
	$sql="select * from ".pre_table."daytrip where daytrip_id='$ID'";
	$row=recordset($sql);
	$country_id=$row['country_id'];
	$city_id=$row['city_id'];
	$daytrip_name=$row['daytrip_name'];	
	$daytrip_price=$row['daytrip_price'];	
	$daytrip_brief=$row['daytrip_brief'];
	$daytrip_content=$row['daytrip_content'];	
	$daytrip_position=$row['daytrip_position'];	
	$daytrip_isdestination=$row['daytrip_isdestination'];	
	$daytrip_isactive=$row['daytrip_isactive'];	
	$daytrip_metadescription=$row['daytrip_metadescription'];	
	$daytrip_metakeyword=$row['daytrip_metakeyword'];	
	$old_daytrip_image=$row['daytrip_image'];
		
	if($row[daytrip_isdestination]==1) $ChkDestination = "checked";			
	if($row[daytrip_isactive]==1) $ChkActive = "checked";			
	
	$xtpl->assign("daytrip_name", $daytrip_name);
	$xtpl->assign("daytrip_price", $daytrip_price);
	$xtpl->assign("daytrip_brief", $daytrip_brief);
	$xtpl->assign("old_daytrip_image", $old_daytrip_image);
	$xtpl->assign("daytrip_position", $daytrip_position);
	$xtpl->assign("daytrip_isdestination", $daytrip_isdestination);
	$xtpl->assign("daytrip_isactive", $daytrip_isactive);
	$xtpl->assign("daytrip_metadescription", $daytrip_metadescription);
	$xtpl->assign("daytrip_metakeyword", $daytrip_metakeyword);
	$xtpl->assign("ChkPagedaytrip", $ChkPagedaytrip);
	$xtpl->assign("ChkDestination", $ChkDestination);
	$xtpl->assign("ChkActive", $ChkActive);
	$xtpl->assign("id", $ID);
	
	$sql_tree="SELECT travelstyle_id FROM ".pre_table."daytrip_travelstyle WHERE daytrip_id='$ID'";
	$rs_tree=execSQL($sql_tree);
	$arr_tree=array();
	while($row_tree=mysql_fetch_array($rs_tree)){
		$arr_tree[] = $row_tree['travelstyle_id'];
	}
	
	$xtpl->assign("type", "EDIT");	
}else{
	// ++ set position
	$stsql = "SELECT daytrip_id from ".pre_table."daytrip WHERE lang='".$lang."'";
	$rssql = execSQL($stsql);
	$numrec=mysql_num_rows($rssql);
	$daytrip_position=$numrec+1;
	$xtpl->assign("daytrip_position", $daytrip_position);
	// -- set position
	
	$xtpl->assign("type", "ADD");	
	$xtpl->assign("ChkActive", "checked");
}

// ++ combo travelstyle
//$sql_travelstyle="SELECT travelstyle_id, travelstyle_name FROM ".pre_table."travelstyle 
//				WHERE lang='".$lang."'";
$sql_travelstyle="SELECT t.travelstyle_id, t.travelstyle_name FROM ".pre_table."travelstyle t, ".pre_table."country_travelstyle ct
				WHERE t.travelstyle_id=ct.travelstyle_id AND ct.country_id='".$country_id."' AND t.lang='".$lang."'";
$rs_travelstyle=execSQL($sql_travelstyle);
$cbo_travelstyle.="<select class=field name='travelstyle_id[]' multiple>";
$cbo_travelstyle.='<option value="">---</option>';
while ($rows = mysql_fetch_array($rs_travelstyle)){
	$cbo_travelstyle.= '<option value="'.$rows['travelstyle_id'].'">'.$space.$rows['travelstyle_name'].'</option>';
}
$cbo_travelstyle.="</select>&nbsp;";
for($i=0; $i < sizeof($arr_tree); $i++){
	$cbo_travelstyle =str_replace("value=\"".$arr_tree[$i]."\"","value=\"".$arr_tree[$i]."\" selected",$cbo_travelstyle);
}
$xtpl->assign("cbo_travelstyle", $cbo_travelstyle);
// -- combo travelstyle

$xtpl->assign("cbo_country", cbo_country($country_id));
$xtpl->assign("cbo_city", cbo_city($country_id, $city_id));

// ++ image
if($old_daytrip_image)
{
	$has_image='<img src='.$path.$old_daytrip_image.' width="50" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:del_image('.$ID.')">'.Delete.'</a>';
}
$xtpl->assign("has_image", $has_image);


$sBasePath="../../FCKeditor/"; 
$oFCKeditor = new FCKeditor('daytrip_content') ;
$oFCKeditor->BasePath	= $sBasePath ;
$oFCKeditor->Value		= $daytrip_content ;
$oFCKeditor->Width	= "100%" ;
$oFCKeditor->Height	= "300" ;


//////////////////////////////////////
$xtpl->parse("MAIN");
eval("?".">".$xtpl->text("MAIN"));
?>